// Definition for singly-linked list.
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct ListNode {
    pub val: i32,
    pub next: Option<Box<ListNode>>,
}

impl ListNode {
    #[inline]
    pub fn new(val: i32) -> Self {
        ListNode { next: None, val }
    }
}

pub trait Vec2ListNode {
    fn from_vec(&self, vec: Vec<i32>) -> Option<Box<Self>>;
}

impl Vec2ListNode for ListNode {
    fn from_vec(&self, vec: Vec<i32>) -> Option<Box<Self>> {
        let mut head = Some(Box::new(Self::new(0)));
        let mut p = head.as_mut();
        for v in vec {
            if let Some(cur) = p {
                cur.next = Some(Box::new(Self::new(v)));
                p = cur.next.as_mut();
            }
        }
        return head.unwrap().next;
    }
}
